<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="AVCaptureDevice 为捕获会话提供输入(如音频或视频)并为特定于硬件的捕获功能提供控制的设备。">
<meta property="og:type" content="article">
<meta property="og:title" content="简单自定义相机">
<meta property="og:url" content="http://yoursite.com/2018/08/27/简单自定义相机/index.html">
<meta property="og:site_name" content="Erhqe">
<meta property="og:description" content="AVCaptureDevice 为捕获会话提供输入(如音频或视频)并为特定于硬件的捕获功能提供控制的设备。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://ws4.sinaimg.cn/large/006tNbRwly1fuo1mjz01kj30nq0dk40k.jpg">
<meta property="og:updated_time" content="2019-07-19T05:40:06.054Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="简单自定义相机">
<meta name="twitter:description" content="AVCaptureDevice 为捕获会话提供输入(如音频或视频)并为特定于硬件的捕获功能提供控制的设备。">
<meta name="twitter:image" content="https://ws4.sinaimg.cn/large/006tNbRwly1fuo1mjz01kj30nq0dk40k.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/08/27/简单自定义相机/"/>





  <title>简单自定义相机 | Erhqe</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Erhqe</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/08/27/简单自定义相机/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Erhqe">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/10.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Erhqe">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">简单自定义相机</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-27T10:12:49+08:00">
                2018-08-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/UI/" itemprop="url" rel="index">
                    <span itemprop="name">UI</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/08/27/简单自定义相机/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2018/08/27/简单自定义相机/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="AVCaptureDevice"><a href="#AVCaptureDevice" class="headerlink" title="AVCaptureDevice"></a>AVCaptureDevice</h4><blockquote>
<p>为捕获会话提供输入(如音频或视频)并为特定于硬件的捕获功能提供控制的设备。<a id="more"></a></p>
</blockquote>
<table>
<thead>
<tr>
<th style="text-align:center">方法以及属性</th>
<th style="text-align:center">注释</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">+ (NSArray *)devices;</td>
<td style="text-align:center">获取手机上的设备</td>
</tr>
<tr>
<td style="text-align:center">+ (NSArray <em>)devicesWithMediaType:(NSString </em>)mediaType;</td>
<td style="text-align:center">获取手机上某种类型的设备</td>
</tr>
<tr>
<td style="text-align:center">+(AVCaptureDevice <em>)defaultDeviceWithMediaType:(NSString </em>)mediaType;</td>
<td style="text-align:center">得到某人制定类型的设备</td>
</tr>
<tr>
<td style="text-align:center">+ (AVCaptureDevice <em>)deviceWithUniqueID:(NSString </em>)deviceUniqueID;</td>
<td style="text-align:center">得到指定ID类型的设备</td>
</tr>
<tr>
<td style="text-align:center">+ (AVAuthorizationStatus)authorizationStatusForMediaType:(NSString *)mediaType;</td>
<td style="text-align:center">获取媒体的授权状态</td>
</tr>
<tr>
<td style="text-align:center">+ (void)requestAccessForMediaType:(NSString *)mediaType completionHandler:(void(^)(BOOL granted))handler;</td>
<td style="text-align:center">为媒体请求用户的权限</td>
</tr>
<tr>
<td style="text-align:center">- (BOOL)lockForConfiguration:(NSError **)outError;</td>
<td style="text-align:center">请求调节硬件配置的权限</td>
</tr>
<tr>
<td style="text-align:center">- (void)unlockForConfiguration;</td>
<td style="text-align:center">放弃调节硬件配置的权限</td>
</tr>
<tr>
<td style="text-align:center">- (BOOL)isFocusModeSupported:(AVCaptureFocusMode)focusMode;</td>
<td style="text-align:center">是否允许调节焦点模式</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureFocusModeLocked</td>
<td style="text-align:center">关闭对焦</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureFocusModeAutoFocus</td>
<td style="text-align:center">自动对焦</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureFocusModeContinuousAutoFocus</td>
<td style="text-align:center">自动连续对焦</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic) AVCaptureFocusMode focusMode;</td>
<td style="text-align:center">对焦模式</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic, readonly, getter=isFocusPointOfInterestSupported) BOOLfocusPointOfInterestSupported;</td>
<td style="text-align:center">是否允许设置自己感兴趣的焦点</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic) CGPoint focusPointOfInterest;</td>
<td style="text-align:center">自己感兴趣的对焦点</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic, readonly, getter=isAdjustingFocus) BOOL adjustingFocus;</td>
<td style="text-align:center">是否允许调节焦点</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic, readonly, getter=isAutoFocusRangeRestrictionSupported)BOOL autoFocusRangeRestrictionSupported;</td>
<td style="text-align:center">自动对焦的范围是否有限制</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic) AVCaptureAutoFocusRangeRestrictionautoFocusRangeRestriction;</td>
<td style="text-align:center">自动对焦的区域限制</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureAutoFocusRangeRestrictionNone</td>
<td style="text-align:center">没有限制</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureAutoFocusRangeRestrictionNear</td>
<td style="text-align:center">近处</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureAutoFocusRangeRestrictionFar</td>
<td style="text-align:center">远处</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic, readonly, getter=isSmoothAutoFocusSupported) BOOLsmoothAutoFocusSupported NS_AVAILABLE_IOS(7_0);</td>
<td style="text-align:center">是否支持平滑对焦</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic, getter=isSmoothAutoFocusEnabled) BOOLsmoothAutoFocusEnabled NS_AVAILABLE_IOS(7_0);</td>
<td style="text-align:center">是否允许平滑对焦</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isAdjustingExposure) BOOL adjustingExposure</td>
<td style="text-align:center">是否允许调节曝光</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)AVCaptureExposureMode exposureMode</td>
<td style="text-align:center">曝光模式</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureExposureModeLocked</td>
<td style="text-align:center">锁定曝光</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureExposureModeAutoExpose</td>
<td style="text-align:center">自动曝光</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureExposureModeContinuousAutoExposure</td>
<td style="text-align:center">自动持续曝光</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureExposureModeCustom</td>
<td style="text-align:center">自定义曝光</td>
</tr>
<tr>
<td style="text-align:center">-(BOOL)isExposureModeSupported:(AVCaptureExposureMode)exposureMode;</td>
<td style="text-align:center">曝光模式是否支持</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)CGPoint exposurePointOfInterest</td>
<td style="text-align:center">感兴趣的曝光点</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isExposurePointOfInterestSupported) BOOLexposurePointOfInterestSupported</td>
<td style="text-align:center">是否支持感兴趣的曝光点调节</td>
</tr>
<tr>
<td style="text-align:center">-(BOOL)isWhiteBalanceModeSupported:(AVCaptureWhiteBalanceMode)whiteBalanceMode</td>
<td style="text-align:center">是否支持白平衡模式</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureWhiteBalanceModeLocked</td>
<td style="text-align:center">锁定</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureWhiteBalanceModeAutoWhiteBalance</td>
<td style="text-align:center">自动白平衡</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance</td>
<td style="text-align:center">自动持续白平衡</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)AVCaptureWhiteBalanceMode whiteBalanceMode</td>
<td style="text-align:center">白平衡模式</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isAdjustingWhiteBalance) BOOL adjustingWhiteBalance</td>
<td style="text-align:center">是否允许调节白平衡</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)CGFloat videoZoomFactor</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">-(void)rampToVideoZoomFactor:(CGFloat)factor withRate:(float)rate</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">-(void)cancelVideoZoomRamp</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isRampingVideoZoom) BOOL rampingVideoZoom</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) BOOL hasFlash</td>
<td style="text-align:center">设备是否有闪光灯</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)AVCaptureFlashMode flashMode</td>
<td style="text-align:center">闪光灯模式</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureFlashModeOff</td>
<td style="text-align:center">关</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureFlashModeOn</td>
<td style="text-align:center">开</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureFlashModeAuto</td>
<td style="text-align:center">自动</td>
</tr>
<tr>
<td style="text-align:center">-(BOOL)isFlashModeSupported:(AVCaptureFlashMode)flashMode</td>
<td style="text-align:center">是否支持设定的闪光灯模式</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isFlashActive) BOOL flashActive</td>
<td style="text-align:center">当前闪光灯是否处于活动状态</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isFlashAvailable) BOOL flashAvailable</td>
<td style="text-align:center">当前闪光灯是否处于可用状态</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) BOOL hasTorch</td>
<td style="text-align:center">当前设备是否有手电筒</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isTorchAvailable) BOOL torchAvailable</td>
<td style="text-align:center">手电筒是否可用</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isTorchActive) BOOL torchActive</td>
<td style="text-align:center">手电筒是否处于活动状态</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float torchLevel</td>
<td style="text-align:center">手电筒亮度调节</td>
</tr>
<tr>
<td style="text-align:center">-(BOOL)isTorchModeSupported:(AVCaptureTorchMode)torchMode</td>
<td style="text-align:center">手电筒模式</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureTorchModeOff</td>
<td style="text-align:center">关</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureTorchModeOn</td>
<td style="text-align:center">开</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureTorchModeAuto</td>
<td style="text-align:center">自动</td>
</tr>
<tr>
<td style="text-align:center">-(BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError**)outError</td>
<td style="text-align:center">调节手电筒的亮度</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isLowLightBoostSupported) BOOL lowLightBoostSupported</td>
<td style="text-align:center">是否支持低亮度下提高亮度</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isLowLightBoostEnabled) BOOL lowLightBoostEnabled</td>
<td style="text-align:center">是否允许低亮度调节</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)BOOL automaticallyEnablesLowLightBoostWhenAvailable</td>
<td style="text-align:center">自动允许低亮状态下提高亮度</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)CMTime activeVideoMinFrameDuration</td>
<td style="text-align:center">最小屏幕的持续时间</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)CMTime activeVideoMaxFrameDuration</td>
<td style="text-align:center">最大屏幕的持续时间</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,getter=isSubjectAreaChangeMonitoringEnabled) BOOLsubjectAreaChangeMonitoringEnabled</td>
<td style="text-align:center">是否允许监视区域的改变，便于重新聚焦,调节白平衡，调节曝光等</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly, getter=isConnected) BOOL connected</td>
<td style="text-align:center">当前设备是否连接</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) AVCaptureDevicePosition position</td>
<td style="text-align:center">当前设备的位置</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureDevicePositionUnspecified</td>
<td style="text-align:center">未制定</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureDevicePositionBack</td>
<td style="text-align:center">后</td>
</tr>
<tr>
<td style="text-align:center">AVCaptureDevicePositionFront</td>
<td style="text-align:center">前</td>
</tr>
<tr>
<td style="text-align:center">-(BOOL)hasMediaType:(NSString *)mediaType</td>
<td style="text-align:center">判断当前设备是否有给定的媒体类型</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) NSString *modelID</td>
<td style="text-align:center">modelID 所有设备相同model的不同ID</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) NSString *localizedName</td>
<td style="text-align:center">设备的本地名字</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) NSString *uniqueID</td>
<td style="text-align:center">uniqueID</td>
</tr>
<tr>
<td style="text-align:center">-(BOOL)supportsAVCaptureSessionPreset:(NSString *)preset</td>
<td style="text-align:center">是否允许捕捉期间预先设置参数</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float lensAperture</td>
<td style="text-align:center">镜头的光圈（只读）</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float lensPosition</td>
<td style="text-align:center">镜头的位置（只读）</td>
</tr>
<tr>
<td style="text-align:center">-(void)setFocusModeLockedWithLensPosition:(float)lensPositioncompletionHandler:(void(^)(CMTime syncTime))handler</td>
<td style="text-align:center">调节镜头的位置</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) CMTime exposureDuration</td>
<td style="text-align:center">曝光时长（只读）</td>
</tr>
<tr>
<td style="text-align:center">-(void)setExposureModeCustomWithDuration:(CMTime)duration ISO:(float)ISO completionHandler:(void(^)(CMTime syncTime))handler</td>
<td style="text-align:center">调解自定义曝光模式和时长</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float exposureTargetOffset</td>
<td style="text-align:center">曝光的偏移量</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float exposureTargetBias</td>
<td style="text-align:center">曝光目标的倾斜</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float maxExposureTargetBias</td>
<td style="text-align:center">最大的倾斜</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float maxExposureTargetBias</td>
<td style="text-align:center">最小的倾斜</td>
</tr>
<tr>
<td style="text-align:center">-(void)setExposureTargetBias:(float)biascompletionHandler:(void(^)(CMTime syncTime))handler</td>
<td style="text-align:center">调节曝光倾斜</td>
</tr>
<tr>
<td style="text-align:center">-(AVCaptureWhiteBalanceChromaticityValues)chromaticityValuesForDeviceWhiteBalanceGains:(AVCaptureWhiteBalanceGains)whiteBalanceGains</td>
<td style="text-align:center">白平衡色度调节</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) AVCaptureWhiteBalanceGains deviceWhiteBalanceGains</td>
<td style="text-align:center">获取白平衡增益</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float maxWhiteBalanceGain</td>
<td style="text-align:center">最大的白平衡增益</td>
</tr>
<tr>
<td style="text-align:center">-(AVCaptureWhiteBalanceGains)deviceWhiteBalanceGainsForChromaticityValues:(AVCaptureWhiteBalanceChromaticityValues)chromaticityValues</td>
<td style="text-align:center">设备的白平衡色彩度</td>
</tr>
<tr>
<td style="text-align:center">-(AVCaptureWhiteBalanceGains)deviceWhiteBalanceGainsForTemperatureAndTintValues:(AVCaptureWhiteBalanceTemperatureAndTintValues)tempAndTintValues</td>
<td style="text-align:center">温度和色彩度的白平衡调节</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) AVCaptureWhiteBalanceGains grayWorldDeviceWhiteBalanceGains</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">-(void)setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:(AVCaptureWhiteBalanceGains)whiteBalanceGains completionHandler:(void(^)(CMTime syncTime))handler</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">-(AVCaptureWhiteBalanceTemperatureAndTintValues)temperatureAndTintValuesForDeviceWhiteBalanceGains:(AVCaptureWhiteBalanceGains)whiteBalanceGains</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,readonly) float ISO</td>
<td style="text-align:center">曝光的ISO值</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic)BOOL automaticallyAdjustsVideoHDREnabled</td>
<td style="text-align:center">是否允许自动调节HDR</td>
</tr>
<tr>
<td style="text-align:center">@property(nonatomic,getter=isVideoHDREnabled) BOOL videoHDREnabled</td>
<td style="text-align:center">是否允许HDR调节</td>
</tr>
</tbody>
</table>
<h5 id="常亮通知"><a href="#常亮通知" class="headerlink" title="常亮通知"></a>常亮通知</h5><table>
<thead>
<tr>
<th style="text-align:center">名</th>
<th style="text-align:center">注释</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center"></td>
</tr>
</tbody>
</table>
<h4 id="AVCaptureDeviceInput"><a href="#AVCaptureDeviceInput" class="headerlink" title="AVCaptureDeviceInput"></a>AVCaptureDeviceInput</h4><blockquote>
<p><code>AVCaptureDeviceInput</code>是用于从对象捕获数据的具体子类。<a href="https://developer.apple.com/documentation/avfoundation/avcaptureinput" target="_blank" rel="noopener"><code>AVCaptureInput</code></a><a href="https://developer.apple.com/documentation/avfoundation/avcapturedevice" target="_blank" rel="noopener"><code>AVCaptureDevice</code></a></p>
</blockquote>
<h4 id="AVCaptureSession"><a href="#AVCaptureSession" class="headerlink" title="AVCaptureSession"></a>AVCaptureSession</h4><blockquote>
<p>管理捕获活动并协调从输入设备到捕获输出的数据流的对象    要执行实时或离线捕获，您需要实例化一个对象并添加适当的输入（例如）和输出（例如）。以下代码片段说明了如何配置捕获设备以记录音频</p>
</blockquote>
<figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];</span><br><span class="line">AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice <span class="symbol">defaultDeviceWithMediaType:</span>AVMediaTypeAudio];</span><br><span class="line">NSError *error = <span class="literal">nil</span>;</span><br><span class="line">AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput <span class="symbol">deviceInputWithDevice:</span>audioCaptureDevice <span class="symbol">error:</span>&amp;error];</span><br><span class="line"><span class="keyword">if</span> (audioInput) &#123;</span><br><span class="line">    [captureSession <span class="symbol">addInput:</span>audioInput];</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span> &#123;</span><br><span class="line">    /<span class="regexp">/ Handle the failure.</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br></pre></td></tr></table></figure>
<h4 id="AVCaptureVideoPreviewLayer"><a href="#AVCaptureVideoPreviewLayer" class="headerlink" title="AVCaptureVideoPreviewLayer"></a>AVCaptureVideoPreviewLayer</h4><blockquote>
<p><code>AVCaptureVideoPreviewLayer</code>是用于<a href="https://developer.apple.com/documentation/quartzcore/calayer" target="_blank" rel="noopener"><code>CALayer</code></a>在输入设备捕获视频时显示视频的子类。您可以将此预览图层与AVCaptureSession结合使用，如以下代码片段所示：</p>
</blockquote>
<figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">AVCaptureSession *captureSession = &lt;<span class="comment">#Get a capture session#&gt;;</span></span><br><span class="line">AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer <span class="symbol">layerWithSession:</span>captureSession];</span><br><span class="line">UIView *aView = &lt;<span class="comment">#The view in which to present the layer#&gt;;</span></span><br><span class="line">previewLayer.frame = aView.bounds; <span class="regexp">//</span> Assume you want the preview layer to fill the view.</span><br><span class="line">[aView.layer <span class="symbol">addSublayer:</span>previewLayer];</span><br></pre></td></tr></table></figure>
<p><strong>简单的大概步骤</strong></p>
<p><img src="https://ws4.sinaimg.cn/large/006tNbRwly1fuo1mjz01kj30nq0dk40k.jpg" alt=""></p>
<h5 id="常见属性"><a href="#常见属性" class="headerlink" title="常见属性"></a>常见属性</h5><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">/<span class="regexp">/捕获设备，通常是前置摄像头，后置摄像头，麦克风（音频输入）</span></span><br><span class="line"><span class="regexp">@property(nonatomic)AVCaptureDevice *device;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/AVCaptureDeviceInput 代表输入设备，他使用AVCaptureDevice 来初始化</span></span><br><span class="line"><span class="regexp">@property(nonatomic)AVCaptureDeviceInput *input;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/当启动摄像头开始捕获输入</span></span><br><span class="line"><span class="regexp">@property(nonatomic)AVCaptureMetadataOutput *output;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span>*faceId*<span class="regexp">/</span></span><br><span class="line"><span class="regexp">@property(assign,nonatomic) NSInteger faceId;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/照片输出流</span></span><br><span class="line"><span class="regexp">@property (nonatomic)AVCaptureStillImageOutput *ImageOutPut;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/session：由他把输入输出结合在一起，并开始启动捕获设备（摄像头）</span></span><br><span class="line"><span class="regexp">@property(nonatomic)AVCaptureSession *session;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/图像预览层，实时显示捕获的图像</span></span><br><span class="line"><span class="regexp">@property(nonatomic)AVCaptureVideoPreviewLayer *previewLayer;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/ ------------- UI --------------</span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/拍照按钮</span></span><br><span class="line"><span class="regexp">@property (nonatomic)UIButton *photoButton;</span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/闪光灯按钮</span></span><br><span class="line"><span class="regexp">@property (nonatomic)UIButton *flashButton;</span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/聚焦</span></span><br><span class="line"><span class="regexp">@property (nonatomic)UIView *focusView;</span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/是否开启闪光灯</span></span><br><span class="line"><span class="regexp">@property (nonatomic)BOOL isflashOn;</span></span><br></pre></td></tr></table></figure>
<h5 id="viewDidLoad"><a href="#viewDidLoad" class="headerlink" title="viewDidLoad"></a>viewDidLoad</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    self.view.backgroundColor = [UIColor clearColor];</span><br><span class="line">    self.faceId = 0;	//初始化FaceId 自动聚焦使用</span><br><span class="line">    if ( [self checkCameraPermission]) &#123;	// 是否获取了相机权限</span><br><span class="line">        </span><br><span class="line">        [self customCamera];	//准备摄像头</span><br><span class="line">        [self initSubViews];	// 初始化UI</span><br><span class="line">        [self focusAtPoint:CGPointMake(0.5, 0.5)];	// 聚焦 以及 曝光</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="获取相机权限"><a href="#获取相机权限" class="headerlink" title="获取相机权限"></a>获取相机权限</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">#pragma mark- 检测相机权限</span><br><span class="line">- (BOOL)checkCameraPermission</span><br><span class="line">&#123;</span><br><span class="line">    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];</span><br><span class="line">    if (authStatus == AVAuthorizationStatusDenied) &#123;</span><br><span class="line">        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@&quot;请打开相机权限&quot; message:@&quot;设置-隐私-相机&quot; delegate:self cancelButtonTitle:@&quot;确定&quot; otherButtonTitles:@&quot;取消&quot;, nil];</span><br><span class="line">        alertView.tag = 100;</span><br><span class="line">        [alertView show];</span><br><span class="line">        return NO;</span><br><span class="line">    &#125;</span><br><span class="line">    else&#123;</span><br><span class="line">        return YES;</span><br><span class="line">    &#125;</span><br><span class="line">    return YES;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="准备摄像头"><a href="#准备摄像头" class="headerlink" title="准备摄像头"></a>准备摄像头</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line">- (void)customCamera</span><br><span class="line">&#123;</span><br><span class="line">    //使用AVMediaTypeVideo 指明self.device代表视频，默认使用后置摄像头进行初始化</span><br><span class="line">    self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];</span><br><span class="line">    //使用设备初始化输入</span><br><span class="line">    self.input = [[AVCaptureDeviceInput alloc]initWithDevice:self.device error:nil];</span><br><span class="line">    //生成输出对象</span><br><span class="line">    self.output = [[AVCaptureMetadataOutput alloc]init];</span><br><span class="line">    </span><br><span class="line">    self.ImageOutPut = [[AVCaptureStillImageOutput alloc]init];</span><br><span class="line">    //生成会话，用来结合输入输出</span><br><span class="line">    self.session = [[AVCaptureSession alloc]init];</span><br><span class="line">    if ([self.session canSetSessionPreset:AVCaptureSessionPreset1280x720]) &#123;</span><br><span class="line">        </span><br><span class="line">        [self.session setSessionPreset:AVCaptureSessionPreset1280x720];</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    if ([self.session canAddInput:self.input]) &#123;</span><br><span class="line">        [self.session addInput:self.input];</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">   </span><br><span class="line">    if ([self.session canAddOutput:self.ImageOutPut]) &#123;</span><br><span class="line">        [self.session addOutput:self.ImageOutPut];</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    //使用self.session，初始化预览层，self.session负责驱动input进行信息的采集，layer负责把图像渲染显示</span><br><span class="line">    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:self.session];</span><br><span class="line">    self.previewLayer.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);</span><br><span class="line">    self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;   //AVLayerVideoGravityResizeAspect  根据手机屏幕缩小</span><br><span class="line">    [self.view.layer addSublayer:self.previewLayer];</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    //请求调节硬件配置的权限</span><br><span class="line">    if ([self.device lockForConfiguration:nil]) &#123;</span><br><span class="line">        </span><br><span class="line">        //闪光灯自动</span><br><span class="line">        if ([self.device isFlashModeSupported:AVCaptureFlashModeAuto]) &#123;</span><br><span class="line">            [self.device setFlashMode:AVCaptureFlashModeAuto];</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        //自动白平衡</span><br><span class="line">        if ([self.device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance]) &#123;</span><br><span class="line">            [self.device setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance];</span><br><span class="line">        &#125;</span><br><span class="line">        //解锁</span><br><span class="line">        [self.device unlockForConfiguration];</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">//    self.output = [[AVCaptureMetadataOutput alloc] init];</span><br><span class="line">//    [self.session addOutput:self.output];</span><br><span class="line">//    [self.output setMetadataObjectsDelegate:self queue: dispatch_get_global_queue(0, 0)];</span><br><span class="line">    </span><br><span class="line">    // 人脸识别</span><br><span class="line">    self.output = [AVCaptureMetadataOutput new];</span><br><span class="line">    [self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];</span><br><span class="line">    if ([self.session canAddOutput:self.output]) &#123;</span><br><span class="line">        </span><br><span class="line">        [self.session addOutput:self.output];</span><br><span class="line">    &#125;</span><br><span class="line">    self.output.metadataObjectTypes = @[AVMetadataObjectTypeFace];</span><br><span class="line">    </span><br><span class="line">    //开始启动</span><br><span class="line">    [self.session startRunning];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="初始化UI"><a href="#初始化UI" class="headerlink" title="初始化UI"></a>初始化UI</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">- (void)initSubViews</span><br><span class="line">&#123;</span><br><span class="line">    UIButton *btn = [UIButton new];</span><br><span class="line">    btn.frame = CGRectMake(20, 20, 40, 40);</span><br><span class="line">    [btn setTitle:@&quot;取消&quot; forState:UIControlStateNormal];</span><br><span class="line">    [btn addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventTouchUpInside];</span><br><span class="line">    [self.view addSubview:btn];</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    self.photoButton = [UIButton new];</span><br><span class="line">    self.photoButton.frame = CGRectMake(KScreenWidth/2.0-30, KScreenHeight-100, 60, 60);</span><br><span class="line">    [self.photoButton setImage:[UIImage imageNamed:@&quot;photograph&quot;] forState:UIControlStateNormal];</span><br><span class="line">     [self.photoButton addTarget:self action:@selector(shutterCamera) forControlEvents:UIControlEventTouchUpInside];</span><br><span class="line">    [self.view addSubview:self.photoButton];</span><br><span class="line">    </span><br><span class="line">    self.focusView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];</span><br><span class="line">    self.focusView.layer.borderWidth = 1.0;</span><br><span class="line">    self.focusView.layer.borderColor = [UIColor colorWithRed:222 / 255.0 green:163 / 255.0 blue:44 / 255.0 alpha:1].CGColor;</span><br><span class="line">    self.focusView.layer.cornerRadius = 1;</span><br><span class="line">    self.focusView.layer.masksToBounds = YES;</span><br><span class="line">    [self.view addSubview:self.focusView];</span><br><span class="line">    self.focusView.hidden = YES;</span><br><span class="line">    </span><br><span class="line">    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];</span><br><span class="line">    [leftButton setTitle:@&quot;切换&quot; forState:UIControlStateNormal];</span><br><span class="line">    leftButton.titleLabel.textAlignment = NSTextAlignmentCenter;</span><br><span class="line">    [leftButton sizeToFit];</span><br><span class="line">    leftButton.center = CGPointMake((KScreenWidth - 60)/2.0/2.0, KScreenHeight-70);</span><br><span class="line">    [leftButton addTarget:self action:@selector(changeCamera) forControlEvents:UIControlEventTouchUpInside];</span><br><span class="line">    [self.view addSubview:leftButton];</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    self.flashButton = [UIButton buttonWithType:UIButtonTypeCustom];</span><br><span class="line">    [ self.flashButton setTitle:@&quot;闪光灯关&quot; forState:UIControlStateNormal];</span><br><span class="line">    self.flashButton.titleLabel.textAlignment = NSTextAlignmentCenter;</span><br><span class="line">    [self.flashButton sizeToFit];</span><br><span class="line">    self.flashButton.center = CGPointMake(KScreenWidth - (KScreenWidth - 60)/2.0/2.0, KScreenHeight-70);</span><br><span class="line">    [ self.flashButton addTarget:self action:@selector(FlashOn) forControlEvents:UIControlEventTouchUpInside];</span><br><span class="line">    [self.view addSubview: self.flashButton];</span><br><span class="line">    </span><br><span class="line">    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(focusGesture:)];</span><br><span class="line">    [self.view addGestureRecognizer:tapGesture];</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(10, 500, 400, 35)];</span><br><span class="line">    slider.maximumValue = 1;</span><br><span class="line">    slider.minimumValue = 0;</span><br><span class="line">    [slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];</span><br><span class="line">    [self.view addSubview:slider];</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="聚焦-以及-曝光"><a href="#聚焦-以及-曝光" class="headerlink" title="聚焦 以及 曝光"></a>聚焦 以及 曝光</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">#pragma mark - 点击屏幕时的焦点 曝光</span><br><span class="line">- (void)focusAtPoint:(CGPoint)point&#123;</span><br><span class="line">    CGSize size = self.view.bounds.size;</span><br><span class="line">    // focusPoint 函数后面Point取值范围是取景框左上角（0，0）到取景框右下角（1，1）之间,按这个来但位置就是不对，只能按上面的写法才可以。前面是点击位置的y/PreviewLayer的高度，后面是1-点击位置的x/PreviewLayer的宽度</span><br><span class="line">    CGPoint focusPoint = CGPointMake( point.y /size.height ,1 - point.x/size.width );</span><br><span class="line">    </span><br><span class="line">    if ([self.device lockForConfiguration:nil]) &#123;</span><br><span class="line">//        是否允许调节焦点模式</span><br><span class="line">        if ([self.device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) &#123;</span><br><span class="line">            [self.device setFocusPointOfInterest:focusPoint];   //是否允许设置自己感兴趣的焦点</span><br><span class="line">            </span><br><span class="line">            /*</span><br><span class="line">             AVCaptureFocusModeLocked      关闭对焦</span><br><span class="line">             AVCaptureFocusModeAutoFocus   自动对焦</span><br><span class="line">             AVCaptureFocusModeContinuousAutoFocus  自动连续对焦</span><br><span class="line">             */</span><br><span class="line">            [self.device setFocusMode:AVCaptureFocusModeAutoFocus];</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        //曝光模式是否支持</span><br><span class="line">        /*</span><br><span class="line">         //曝光模式</span><br><span class="line">         @property(nonatomic)AVCaptureExposureMode exposureMode</span><br><span class="line">         AVCaptureExposureModeLocked                 锁定曝光</span><br><span class="line">         AVCaptureExposureModeAutoExpose             自动曝光</span><br><span class="line">         AVCaptureExposureModeContinuousAutoExposure  自动持续曝光</span><br><span class="line">         AVCaptureExposureModeCustom                 自定义曝光</span><br><span class="line">         */</span><br><span class="line">        if ([self.device isExposureModeSupported:AVCaptureExposureModeAutoExpose ]) &#123;</span><br><span class="line">            [self.device setExposurePointOfInterest:focusPoint];    //感兴趣的曝光点</span><br><span class="line">            //曝光量调节</span><br><span class="line">            [self.device setExposureMode:AVCaptureExposureModeAutoExpose];</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        // 放弃调节硬件配置的权限</span><br><span class="line">        [self.device unlockForConfiguration];</span><br><span class="line">        </span><br><span class="line">        _focusView.center = point;</span><br><span class="line">        _focusView.hidden = NO;</span><br><span class="line">        [UIView animateWithDuration:0.3 animations:^&#123;</span><br><span class="line">            _focusView.transform = CGAffineTransformMakeScale(1.25, 1.25);</span><br><span class="line">        &#125;completion:^(BOOL finished) &#123;</span><br><span class="line">            [UIView animateWithDuration:0.5 animations:^&#123;</span><br><span class="line">                _focusView.transform = CGAffineTransformIdentity;</span><br><span class="line">            &#125; completion:^(BOOL finished) &#123;</span><br><span class="line">                _focusView.hidden = YES;</span><br><span class="line">            &#125;];</span><br><span class="line">        &#125;];</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="调整曝光-调节焦距-数码变焦"><a href="#调整曝光-调节焦距-数码变焦" class="headerlink" title="调整曝光 - 调节焦距 - 数码变焦"></a>调整曝光 - 调节焦距 - 数码变焦</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line">#pragma mark - 调整曝光 - 调节焦距 - 数码变焦</span><br><span class="line">- (void)sliderValueChange:(UISlider *)slider&#123;</span><br><span class="line"></span><br><span class="line">    // 调整曝光 调节ISO，光感度  sliderValue = 0~1.0</span><br><span class="line">//    AVCaptureDevice *captureDevice = [self.input device];</span><br><span class="line">//    NSError *error;</span><br><span class="line">//    if ([captureDevice lockForConfiguration:&amp;error]) &#123;</span><br><span class="line">//        CGFloat minISO = captureDevice.activeFormat.minISO;</span><br><span class="line">//        CGFloat maxISO = captureDevice.activeFormat.maxISO;</span><br><span class="line">//        // 调节ISO为全范围</span><br><span class="line">//        CGFloat currentISO = (maxISO - minISO) * slider.value + minISO;</span><br><span class="line">//</span><br><span class="line">//        [captureDevice setExposureModeCustomWithDuration:AVCaptureExposureDurationCurrent ISO:currentISO completionHandler:nil];</span><br><span class="line">//        [captureDevice unlockForConfiguration];</span><br><span class="line">//</span><br><span class="line">//    &#125;else&#123;</span><br><span class="line">//            // Handle the error appropriately.</span><br><span class="line">//</span><br><span class="line">//        &#125;</span><br><span class="line"> </span><br><span class="line">    //调节焦距 0~1.0</span><br><span class="line">//    AVCaptureDevice *captureDevice = [self.input device];</span><br><span class="line">//    NSError *error; if ([captureDevice lockForConfiguration:&amp;error]) &#123;</span><br><span class="line">//        if ([captureDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus])&#123;</span><br><span class="line">//            [captureDevice setFocusModeLockedWithLensPosition:slider.value completionHandler:nil];</span><br><span class="line">//            [captureDevice unlockForConfiguration];</span><br><span class="line">//</span><br><span class="line">//    &#125;else&#123;</span><br><span class="line">//        // Handle the error appropriately.</span><br><span class="line">//</span><br><span class="line">//        &#125;</span><br><span class="line">//    &#125;</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    // 数码变焦 1~3 拉近 缩小</span><br><span class="line">//    AVCaptureDevice *captureDevice = [self.input device];</span><br><span class="line">//    NSError *error;</span><br><span class="line">//    if ([captureDevice lockForConfiguration:&amp;error]) &#123;</span><br><span class="line">//        [captureDevice rampToVideoZoomFactor:slider.value withRate:50];</span><br><span class="line">//    &#125;else&#123;</span><br><span class="line">//        // Handle the error appropriately.</span><br><span class="line">//</span><br><span class="line">//    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="点击屏幕事件"><a href="#点击屏幕事件" class="headerlink" title="点击屏幕事件"></a>点击屏幕事件</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">- (void)focusGesture:(UITapGestureRecognizer*)gesture&#123;</span><br><span class="line">    CGPoint point = [gesture locationInView:gesture.view];</span><br><span class="line">    [self focusAtPoint:point];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="识别到人脸焦点以及曝光"><a href="#识别到人脸焦点以及曝光" class="headerlink" title="识别到人脸焦点以及曝光"></a>识别到人脸焦点以及曝光</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">- (void)setSelectSection:(CGPoint)point&#123;</span><br><span class="line">    CGSize size = self.view.bounds.size;</span><br><span class="line">    // focusPoint 函数后面Point取值范围是取景框左上角（0，0）到取景框右下角（1，1）之间,按这个来但位置就是不对，只能按上面的写法才可以。前面是点击位置的y/PreviewLayer的高度，后面是1-点击位置的x/PreviewLayer的宽度</span><br><span class="line">    CGPoint focusPoint = CGPointMake( point.y /size.height ,1 - point.x/size.width );</span><br><span class="line">    </span><br><span class="line">    if ([self.device lockForConfiguration:nil]) &#123;</span><br><span class="line">        </span><br><span class="line">        if ([self.device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) &#123;</span><br><span class="line">            [self.device setFocusPointOfInterest:focusPoint];</span><br><span class="line">            [self.device setFocusMode:AVCaptureFocusModeAutoFocus];</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        if ([self.device isExposureModeSupported:AVCaptureExposureModeAutoExpose ]) &#123;</span><br><span class="line">            [self.device setExposurePointOfInterest:focusPoint];</span><br><span class="line">            //曝光量调节</span><br><span class="line">            [self.device setExposureMode:AVCaptureExposureModeAutoExpose];</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        [self.device unlockForConfiguration];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="闪光灯"><a href="#闪光灯" class="headerlink" title="闪光灯"></a>闪光灯</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">- (void)FlashOn&#123;</span><br><span class="line">    </span><br><span class="line">    if ([_device lockForConfiguration:nil]) &#123;</span><br><span class="line">        if (_isflashOn) &#123;</span><br><span class="line">            if ([_device isFlashModeSupported:AVCaptureFlashModeOff]) &#123;</span><br><span class="line">                [_device setFlashMode:AVCaptureFlashModeOff];</span><br><span class="line">                _isflashOn = NO;</span><br><span class="line">                [_flashButton setTitle:@&quot;闪光灯关&quot; forState:UIControlStateNormal];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;else&#123;</span><br><span class="line">            if ([_device isFlashModeSupported:AVCaptureFlashModeOn]) &#123;</span><br><span class="line">                [_device setFlashMode:AVCaptureFlashModeOn];</span><br><span class="line">                _isflashOn = YES;</span><br><span class="line">                [_flashButton setTitle:@&quot;闪光灯开&quot; forState:UIControlStateNormal];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        [_device unlockForConfiguration];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="切换摄像头"><a href="#切换摄像头" class="headerlink" title="切换摄像头"></a>切换摄像头</h5><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="keyword">void</span>)changeCamera&#123;</span><br><span class="line">    <span class="comment">//获取摄像头的数量</span></span><br><span class="line">    <span class="built_in">NSUInteger</span> cameraCount = [[<span class="built_in">AVCaptureDevice</span> devicesWithMediaType:<span class="built_in">AVMediaTypeVideo</span>] count];</span><br><span class="line">    <span class="comment">//摄像头小于等于1的时候直接返回</span></span><br><span class="line">    <span class="keyword">if</span> (cameraCount &lt;= <span class="number">1</span>) <span class="keyword">return</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="built_in">AVCaptureDevice</span> *newCamera = <span class="literal">nil</span>;</span><br><span class="line">    <span class="built_in">AVCaptureDeviceInput</span> *newInput = <span class="literal">nil</span>;</span><br><span class="line">    <span class="comment">//获取当前相机的方向(前还是后)</span></span><br><span class="line">    <span class="built_in">AVCaptureDevicePosition</span> position = [[<span class="keyword">self</span>.input device] position];</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//为摄像头的转换加转场动画</span></span><br><span class="line">    <span class="built_in">CATransition</span> *animation = [<span class="built_in">CATransition</span> animation];</span><br><span class="line">    animation.timingFunction = [<span class="built_in">CAMediaTimingFunction</span> functionWithName:kCAMediaTimingFunctionEaseInEaseOut];</span><br><span class="line">    animation.duration = <span class="number">0.5</span>;</span><br><span class="line">    animation.type = <span class="string">@"oglFlip"</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span> (position == <span class="built_in">AVCaptureDevicePositionFront</span>) &#123;</span><br><span class="line">        <span class="comment">//获取后置摄像头</span></span><br><span class="line">        newCamera = [<span class="keyword">self</span> cameraWithPosition:<span class="built_in">AVCaptureDevicePositionBack</span>];</span><br><span class="line">        animation.subtype = kCATransitionFromLeft;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="comment">//获取前置摄像头</span></span><br><span class="line">        newCamera = [<span class="keyword">self</span> cameraWithPosition:<span class="built_in">AVCaptureDevicePositionFront</span>];</span><br><span class="line">        animation.subtype = kCATransitionFromRight;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.previewLayer addAnimation:animation forKey:<span class="literal">nil</span>];</span><br><span class="line">    <span class="comment">//输入流</span></span><br><span class="line">    newInput = [<span class="built_in">AVCaptureDeviceInput</span> deviceInputWithDevice:newCamera error:<span class="literal">nil</span>];</span><br><span class="line">  </span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span> (newInput != <span class="literal">nil</span>) &#123;</span><br><span class="line">        </span><br><span class="line">        [<span class="keyword">self</span>.session beginConfiguration];</span><br><span class="line">        <span class="comment">//先移除原来的input</span></span><br><span class="line">        [<span class="keyword">self</span>.session removeInput:<span class="keyword">self</span>.input];</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">if</span> ([<span class="keyword">self</span>.session canAddInput:newInput]) &#123;</span><br><span class="line">            [<span class="keyword">self</span>.session addInput:newInput];</span><br><span class="line">            <span class="keyword">self</span>.input = newInput;</span><br><span class="line">            </span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">//如果不能加现在的input，就加原来的input</span></span><br><span class="line">            [<span class="keyword">self</span>.session addInput:<span class="keyword">self</span>.input];</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        [<span class="keyword">self</span>.session commitConfiguration];</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="获取当前摄像头"><a href="#获取当前摄像头" class="headerlink" title="获取当前摄像头"></a>获取当前摄像头</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">- (AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position&#123;</span><br><span class="line">    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];</span><br><span class="line">    for ( AVCaptureDevice *device in devices )</span><br><span class="line">        if ( device.position == position ) return device;</span><br><span class="line">    return nil;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="拍照"><a href="#拍照" class="headerlink" title="拍照"></a>拍照</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">- (void)shutterCamera</span><br><span class="line">&#123;</span><br><span class="line">    AVCaptureConnection * videoConnection = [self.ImageOutPut connectionWithMediaType:AVMediaTypeVideo];</span><br><span class="line">    if (videoConnection ==  nil) &#123;</span><br><span class="line">        return;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    [self.ImageOutPut captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) &#123;</span><br><span class="line">       </span><br><span class="line">        if (imageDataSampleBuffer == nil) &#123;</span><br><span class="line">            return;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        NSData *imageData =  [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];</span><br><span class="line">        [self saveImageWithImage:[UIImage imageWithData:imageData]];</span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">    &#125;];</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="保存图片到相册"><a href="#保存图片到相册" class="headerlink" title="保存图片到相册"></a>保存图片到相册</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">- (void)saveImageWithImage:(UIImage *)image &#123;</span><br><span class="line">    // 判断授权状态</span><br><span class="line">    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) &#123;</span><br><span class="line">        if (status != PHAuthorizationStatusAuthorized) return;</span><br><span class="line">        </span><br><span class="line">        dispatch_async(dispatch_get_main_queue(), ^&#123;</span><br><span class="line">            NSError *error = nil;</span><br><span class="line">            </span><br><span class="line">            // 保存相片到相机胶卷</span><br><span class="line">            __block PHObjectPlaceholder *createdAsset = nil;</span><br><span class="line">            [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^&#123;</span><br><span class="line">                createdAsset = [PHAssetCreationRequest creationRequestForAssetFromImage:image].placeholderForCreatedAsset;</span><br><span class="line">            &#125; error:&amp;error];</span><br><span class="line">            </span><br><span class="line">            if (error) &#123;</span><br><span class="line">                NSLog(@&quot;保存失败：%@&quot;, error);</span><br><span class="line">                return;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="退出"><a href="#退出" class="headerlink" title="退出"></a>退出</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">- (void)disMiss</span><br><span class="line">&#123;</span><br><span class="line">    [self dismissViewControllerAnimated:YES completion:nil];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="检测相机权限"><a href="#检测相机权限" class="headerlink" title="检测相机权限"></a>检测相机权限</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">#pragma mark- 检测相机权限</span><br><span class="line">- (BOOL)checkCameraPermission</span><br><span class="line">&#123;</span><br><span class="line">    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];</span><br><span class="line">    if (authStatus == AVAuthorizationStatusDenied) &#123;</span><br><span class="line">        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@&quot;请打开相机权限&quot; message:@&quot;设置-隐私-相机&quot; delegate:self cancelButtonTitle:@&quot;确定&quot; otherButtonTitles:@&quot;取消&quot;, nil];</span><br><span class="line">        alertView.tag = 100;</span><br><span class="line">        [alertView show];</span><br><span class="line">        return NO;</span><br><span class="line">    &#125;</span><br><span class="line">    else&#123;</span><br><span class="line">        return YES;</span><br><span class="line">    &#125;</span><br><span class="line">    return YES;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="AlertDelegate"><a href="#AlertDelegate" class="headerlink" title="AlertDelegate"></a>AlertDelegate</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex&#123;</span><br><span class="line">    if (buttonIndex == 0 &amp;&amp; alertView.tag == 100) &#123;</span><br><span class="line">        </span><br><span class="line">        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];</span><br><span class="line">        </span><br><span class="line">        if([[UIApplication sharedApplication] canOpenURL:url]) &#123;</span><br><span class="line">            </span><br><span class="line">            [[UIApplication sharedApplication] openURL:url];</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    if (buttonIndex == 1 &amp;&amp; alertView.tag == 100) &#123;</span><br><span class="line">        </span><br><span class="line">        [self disMiss];</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/08/22/Const/" rel="next" title="Const">
                <i class="fa fa-chevron-left"></i> Const
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/10/07/NetWrok/" rel="prev" title="NetWrok">
                NetWrok <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/10.png"
                alt="Erhqe" />
            
              <p class="site-author-name" itemprop="name">Erhqe</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">70</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">31</span>
                  <span class="site-state-item-name">categories</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">tags</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#AVCaptureDevice"><span class="nav-number">1.</span> <span class="nav-text">AVCaptureDevice</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#常亮通知"><span class="nav-number">1.1.</span> <span class="nav-text">常亮通知</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#AVCaptureDeviceInput"><span class="nav-number">2.</span> <span class="nav-text">AVCaptureDeviceInput</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#AVCaptureSession"><span class="nav-number">3.</span> <span class="nav-text">AVCaptureSession</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#AVCaptureVideoPreviewLayer"><span class="nav-number">4.</span> <span class="nav-text">AVCaptureVideoPreviewLayer</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#常见属性"><span class="nav-number">4.1.</span> <span class="nav-text">常见属性</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#viewDidLoad"><span class="nav-number">4.2.</span> <span class="nav-text">viewDidLoad</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#获取相机权限"><span class="nav-number">4.3.</span> <span class="nav-text">获取相机权限</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#准备摄像头"><span class="nav-number">4.4.</span> <span class="nav-text">准备摄像头</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#初始化UI"><span class="nav-number">4.5.</span> <span class="nav-text">初始化UI</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#聚焦-以及-曝光"><span class="nav-number">4.6.</span> <span class="nav-text">聚焦 以及 曝光</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#调整曝光-调节焦距-数码变焦"><span class="nav-number">4.7.</span> <span class="nav-text">调整曝光 - 调节焦距 - 数码变焦</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#点击屏幕事件"><span class="nav-number">4.8.</span> <span class="nav-text">点击屏幕事件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#识别到人脸焦点以及曝光"><span class="nav-number">4.9.</span> <span class="nav-text">识别到人脸焦点以及曝光</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#闪光灯"><span class="nav-number">4.10.</span> <span class="nav-text">闪光灯</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#切换摄像头"><span class="nav-number">4.11.</span> <span class="nav-text">切换摄像头</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#获取当前摄像头"><span class="nav-number">4.12.</span> <span class="nav-text">获取当前摄像头</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#拍照"><span class="nav-number">4.13.</span> <span class="nav-text">拍照</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#保存图片到相册"><span class="nav-number">4.14.</span> <span class="nav-text">保存图片到相册</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#退出"><span class="nav-number">4.15.</span> <span class="nav-text">退出</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#检测相机权限"><span class="nav-number">4.16.</span> <span class="nav-text">检测相机权限</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#AlertDelegate"><span class="nav-number">4.17.</span> <span class="nav-text">AlertDelegate</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Erhqe</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'TiAY2J24ECwQH9uLYsoJpgIK-gzGzoHsz',
        appKey: 'Y9PiVrPXVmfNsv4Aa6cPsADG',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
